<div class="form">

    <?php
        $form = $this->beginWidget('CActiveForm', array(
            'id' => 'contracts-form',
            'enableAjaxValidation' => false,
                ));
    ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>
    <div class="row" style="height:80px">
        <table style=" width: 1000px;">
            <tr>
                <td style="  width: 544px;">
                    <label> Customer <a
                            href="index.php?r=Customers/update&id=<?= $model->customer->custno ?>"><?= $model->customer->custno ?></a>
                    </label>

                    <div class="clear"></div>
                    <div class="data-model"  style="width:454px;">

                        <?php echo $model->customer->firstname . ' ' . $model->customer->lastname ?>  <br/>
                        <?php echo $model->customer->add1 ?> <br/>
                        <?php echo $model->customer->city ?>, <?php echo $model->customer->state ?>
                        <?php echo $model->customer->zip ?>
                        <br/>
                    </div>
                    <br clear="all">


                </td>
                <td id="ext-gen1159">


                    <label>Location - <a
                            href="index.php?r=contracts&custno=<?php echo $model->customer->custno; ?>&locno=<?php echo $model->location->locno; ?>"><?php echo $model->location->locno; ?></a></label>

                    <div class="clear"></div>
                    <div class='model-data'
                         style="width:454px;"><?= $model->location->locname ?> <?php echo $model->location->locnickname; ?>
                        <br>
                        <?= $model->location->add1 ?><br/>
                        <?= $model->location->city . ' ' . $model->location->state . ' ' . $model->location->zip ?><br/>
                    </div>

                </td>

            </tr>
        </table>

    </div>
    <br clear="both"/> <br clear="both"/> <br clear="both"/>

    <div class="left-column">


        <div class="row short">
            <?php echo $form->labelEx($model, 'contractid'); ?>
            <div class="model-data">
                <?php echo $model->contractid; ?>
            </div>
            <?php echo $form->error($model, 'contractid'); ?>
        </div>


        <div class="row short">
            <?php echo $form->labelEx($model, 'contractstartdate'); ?>
            <?php
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    'attribute' => 'contractstartdate',
                    'value' => CTimestamp::formatDate('Y-mm-dd', $model->contractstartdate),
                    'options' => array('dateFormat' => 'yy-mm-dd'),
                ));
            ?>
            <?php echo $form->error($model, 'contractstartdate'); ?>
        </div>
        <div class="row short">
            <?php echo $form->labelEx($model, 'contractenddate'); ?>
            <?php
                $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                    'model' => $model,
                    'attribute' => 'contractenddate',
                    'value' => CTimestamp::formatDate('Y-mm-dd', $model->contractenddate),
                    'options' => array('dateFormat' => 'yy-mm-dd'),
                ));
            ?>
            <?php echo $form->error($model, 'contractenddate'); ?>
        </div>


        <div class="row short">
            <?php echo $form->labelEx($model, 'orginalcontractid'); ?>
            <?php echo $form->textField($model, 'orginalcontractid', array('size' => 41, 'maxlength' => 41)); ?>
            <?php echo $form->error($model, 'orginalcontractid'); ?>
        </div>

        <div class="row short">
            <?php echo $form->labelEx($model, 'contractamount'); ?>
            <?php echo $form->textField($model, 'contractamount', array('size' => 41, 'maxlength' => 41)); ?>
            <?php echo $form->error($model, 'contractamount'); ?>
        </div>
        <div class="row short">
            <?php echo $form->labelEx($model, 'pre_quote_amount'); ?>
            <?php echo $form->textField($model, 'pre_quote_amount'); ?>
            <?php echo $form->error($model, 'pre_quote_amount'); ?>
        </div>
        <div class="row short">
            <label>Billed Amount</label>
            <div class="model-data">

                <?php
                    $invSum = 0;
                    foreach ($model->invoiceAndCMList as $invoice)
                    {
                        $invSum+= $invoice->getAmountWithDiscount();
                    }


                    echo number_format($invSum, 2);
                ?>
            </div>
        </div>

        <div class="row short alarm">
<?php echo $form->labelEx($model, 'area1accountno'); ?>
            <?php echo $form->textField($model, 'area1accountno'); ?>
            <?php echo $form->error($model, 'area1accountno'); ?>
        </div>
        <div class="row short alarm">
<?php echo $form->labelEx($model, 'area1description'); ?>
            <?php echo $form->textField($model, 'area1description'); ?>
            <?php echo $form->error($model, 'area1description'); ?>
        </div>

        <div class="row short">
<?php $remainingDay = ContractUtil::calculateRemainingDay($model); ?>

            <label>Remaining Days</label>
            <div class="model-data">
<?php
    echo $remainingDay;
?>
            </div>



        </div>
        <div class="row short">
            <label>Billing Status</label>
<?php echo $form->dropDownList($model, 'billingstatus', CHtml::listData(Dropdowns::model()->findAll('type = "C-BS"'), 'id', 'name')); ?>
        </div>

    </div>
    <div class="right-column">

        <div class="row short">
<?php echo $form->labelEx($model, 'salesperson'); ?>
            <?php
                $data = Customers::model()->getSalePersonList();
                echo $form->dropDownList($model, 'salesperson', $data);
            ?>
            <?php echo $form->error($model, 'salesperson'); ?>
        </div>


        <div class="row short">
<?php echo $form->labelEx($model, 'contractype'); ?>
            <?php echo $form->dropDownList($model, 'contractype', ContractType::getListData()); ?>
            <?php echo $form->error($model, 'contractype'); ?>
        </div>


        <div class="row short">
<?php echo $form->labelEx($model, 'jobno'); ?>
            <?php echo $form->dropDownList($model, 'jobno', Jobs::getJobByLocation($model->custno, $model->locno)); ?>
            <?php echo $form->error($model, 'jobno'); ?>
        </div>

        <div class="row short">
<?php
    //if(!$model->quoteCount):
    if (true):
        ?>

                    <?php echo $form->labelEx($model, 'billtype'); ?>
                    <?php
                    echo $form->dropDownList($model, 'billtype', $model->getBillTypeList());
                    ?>
                    <?php echo $form->error($model, 'billtype'); ?>

                <?php else: ?>
                    <?php echo $form->labelEx($model, 'billtype'); ?>
                    <?php
                    echo $form->dropDownList($model, 'billtype', $model->getBillTypeList(), array('disabled' => 'disabled'));
                    ?>

                    <?php echo $form->error($model, 'billtype'); ?>
            <?php endif; ?>
        </div>
        <div class="row short invoiceemail">
            <?php echo $form->labelEx($model, 'invoiceemail'); ?>
<?php echo $form->textField($model, 'invoiceemail'); ?>
            <?php echo $form->error($model, 'invoiceemail'); ?>
        </div>

        <div class="row short">
<?php echo $form->labelEx($model, 'purchasedby'); ?>
<?php echo $form->textField($model, 'purchasedby'); ?>
            <?php echo $form->error($model, 'purchasedby'); ?>
        </div>

        <div class="row short">
            <label>Monthly Cost</label>
            <div class="model-data">

<?php
    if (false)
    {
        $invSum = 0;
        foreach ($model->invoiceList as $invoice)
        {
            $invSum+= $invoice->amountcharge;
        }

        foreach ($model->cmList as $invoice)
        {
            $invSum-= $invoice->amountchage;
        }
        echo number_format(round($invSum / 12, 2), 2);
    }
    else
    {
        echo number_format(round($model->pre_quote_amount / 12, 2), 2);
    }
?>
            </div>
        </div>
        <div class="row short replace-invoiceemail">

        </div>


        <div class="row short">
            
            
                <?php if ($renewContract = ContractUtil::findRenewContract($model)): ?>
                <label >Renewed</label>
                <div class="model-data">
                        <a href="<?php echo $this->createUrl('/contracts/update', array('contractid' => $renewContract->contractid)); ?>"
                           target="_blank"
                           ><?= $renewContract->contractid; ?></a>
                </div>
                    <?php elseif ($remainingDay < 45): ?>
                <label >Renewal</label>
                <div class="model-data">
                        <a class="add-button" href="javascript:void(0)" id="renewContract" onclick="">Renew Contract</a>
                        </div>
                <?php endif; ?>
            </div>
        <div class="row short">
            <?php echo $form->labelEx($model, 'status'); ?>
            <?php
                $data = CHtml::listData(ContractStatus::model()->findAll('inactive=0'), 'id', 'description');
                echo $form->dropDownList($model, 'status', $data);
            ?>
<?php echo $form->error($model, 'status'); ?>
        </div>
        </div>

        
   


<?php $this->endWidget(); ?>

</div><!-- form -->
